package com.ruoyi.web.controller.proxy;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.proxy.domain.ProxyRoute;
import com.ruoyi.proxy.service.IProxyRouteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 代理路由Controller
 *
 * @author ruoyi
 * @date 2025-11-18
 */
@RestController
@RequestMapping("/proxy/route")
public class ProxyRouteController extends BaseController
{
    @Autowired
    private IProxyRouteService proxyRouteService;

    /**
     * 查询代理路由列表
     */
    @PreAuthorize("@ss.hasPermi('proxy:route:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProxyRoute proxyRoute)
    {
        startPage();
        List<ProxyRoute> list = proxyRouteService.selectProxyRouteList(proxyRoute);
        return getDataTable(list);
    }

    /**
     * 导出代理路由列表
     */
    @PreAuthorize("@ss.hasPermi('proxy:route:export')")
    @Log(title = "代理路由", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProxyRoute proxyRoute)
    {
        List<ProxyRoute> list = proxyRouteService.selectProxyRouteList(proxyRoute);
        ExcelUtil<ProxyRoute> util = new ExcelUtil<ProxyRoute>(ProxyRoute.class);
        util.exportExcel(response, list, "代理路由数据");
    }

    /**
     * 获取代理路由详细信息
     */
    @PreAuthorize("@ss.hasPermi('proxy:route:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(proxyRouteService.selectProxyRouteById(id));
    }

    /**
     * 新增代理路由
     */
    @PreAuthorize("@ss.hasPermi('proxy:route:add')")
    @Log(title = "代理路由", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProxyRoute proxyRoute)
    {
        return toAjax(proxyRouteService.insertProxyRoute(proxyRoute));
    }

    /**
     * 修改代理路由
     */
    @PreAuthorize("@ss.hasPermi('proxy:route:edit')")
    @Log(title = "代理路由", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProxyRoute proxyRoute)
    {
        return toAjax(proxyRouteService.updateProxyRoute(proxyRoute));
    }

    /**
     * 删除代理路由
     */
    @PreAuthorize("@ss.hasPermi('proxy:route:remove')")
    @Log(title = "代理路由", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(proxyRouteService.deleteProxyRouteByIds(ids));
    }
}
